/**
 * File: CountSequences.java
 * Created by: mhaimel
 * Created on: 21 May 2009
 * CVS:  $Id: CountSequences.java,v 1.1 2009/06/19 13:02:49 mhaimel Exp $
 */
package uk.ac.ebi.velvet;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import uk.ac.ebi.curtain.utils.data.FileType;
import uk.ac.ebi.curtain.utils.data.ReadType;
import uk.ac.ebi.curtain.utils.file.EntryMapper;
import uk.ac.ebi.curtain.utils.file.EntryMapperBean;
import uk.ac.ebi.curtain.utils.file.FileInfo;

/**
 * @author mhaimel
 *
 */
public class CountSequences {
	private Log log = LogFactory.getLog(this.getClass());
	
	private List<FileInfo> fiList = new ArrayList<FileInfo>();
	private Long gEntryCnt = 0L;
	private Long gBpCnt = 0L;
	private Long lEntryCnt = 0L;
	private Long lBpCnt = 0L;
	
	
	private void add(FileInfo fi) {
		fiList.add(fi);
	}
	
	private void process() {
		for(FileInfo fi : fiList){
			lEntryCnt = 0l;
			lBpCnt = 0l;
			fi.parse(new EntryMapper(){
				
				@Override
				public void mapEntry(EntryMapperBean bean) {
					process(bean);
				}});
			System.out.println(fi.getName()+"\t"+lEntryCnt+"\t"+lBpCnt);
		}
		System.out.println("Totol:\t"+gEntryCnt+"\t"+gBpCnt);
	}
	
	private final void process(EntryMapperBean bean){
		++gEntryCnt;
		++lEntryCnt;
		gBpCnt += bean.getSequence().length();
		lBpCnt += bean.getSequence().length();
	}
	
	public static void main(String[] args) {
		
		File dir = new File("/homes/mhaimel/resources/velvetProd/input/helminth/capillar");
		CountSequences cCnt = new CountSequences();
		for(File f : dir.listFiles(new FileFilter(){
			@Override
			public boolean accept(File pathname) {
				return pathname.getName().endsWith(".fna");
			}})){
			FileInfo fi = new FileInfo(f,FileType.fasta,ReadType.Short);
			cCnt.add(fi);
		};
		cCnt.process();
	}
}
